package com.miyake.client.datamanage;

import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.googlecode.gchart.client.GChart;
import com.googlecode.gchart.client.GChart.Curve;
import com.googlecode.gchart.client.GChart.SymbolType;
import com.miyake.client.DataService;
import com.miyake.client.DataServiceAsync;

public class OverlayPage {
	private DataServiceAsync service = DataService.Util.getInstance();
	public OverlayPage(List<NodeProperty> node, VerticalPanel panel) {
		final GChart chart = new GChart();
		panel.add(chart);
		for (NodeProperty n : node) {
			if (n.getType().equals(NodeProperty.PLOT)) {
				service.getPlot(n.getKey(), 500, new AsyncCallback<PlotData>() {
					@Override
					public void onFailure(Throwable caught) {
					}

					@Override
					public void onSuccess(PlotData result) {
						chart.addCurve();
						Curve curve = chart.getCurve(chart.getNCurves()-1);
						curve.getSymbol().setHeight(0);
						curve.getSymbol().setWidth(0);
						curve.getSymbol().setSymbolType(SymbolType.LINE);
						double x = 0;
						for (double y : result.getY()) {
							curve.addPoint(x, y);
							x += 1;
						}
						chart.update();
					}
				});
			}
		}
	}

}
